package org.erepublik.company.xml;

import java.io.InputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import org.erepublik.company.generated.CompanyT;
import org.erepublik.company.generated.CountriesT;
import org.erepublik.company.generated.IndustriesT;
import org.erepublik.company.generated.OffersT;
import org.erepublik.company.generated.RegionsT;
import org.erepublik.company.generated.RegionsTT;
import org.erepublik.company.generated.TaxesT;
import org.erepublik.company.generated.monetarymarket.MMOffersT;

/**
 * Klasa z metodami parsujacymi xmle do obiektow jaxbowuych
 *
 * @author Kacper Gorski 'Railman' railman85@gmail.com
 */
public class XMLParsersers {

	@SuppressWarnings("unchecked")
	public static CountriesT parseCountries(InputStream inputStream) throws JAXBException {
		JAXBContext jc = JAXBContext.newInstance("org.erepublik.company.generated");
		Unmarshaller u = jc.createUnmarshaller();
		JAXBElement jaxbEl = (JAXBElement) u.unmarshal( inputStream );
		CountriesT jaxBObject = (CountriesT) jaxbEl.getValue();
		return jaxBObject;
	}
	
	
	@SuppressWarnings("unchecked")
	public static IndustriesT parseProductTypes(InputStream inputStream) throws JAXBException {
		JAXBContext jc = JAXBContext.newInstance("org.erepublik.company.generated");
		Unmarshaller u = jc.createUnmarshaller();
		JAXBElement jaxbEl = (JAXBElement) u.unmarshal( inputStream );
		IndustriesT jaxBObject = (IndustriesT) jaxbEl.getValue();
		return jaxBObject;
	}
	
	@SuppressWarnings("unchecked")
	public static OffersT parseProducts(InputStream inputStream) throws JAXBException {
		JAXBContext jc = JAXBContext.newInstance("org.erepublik.company.generated");
		Unmarshaller u = jc.createUnmarshaller();
		JAXBElement jaxbEl = (JAXBElement) u.unmarshal( inputStream );
		OffersT jaxBObject = (OffersT) jaxbEl.getValue();
		return jaxBObject;
	}
	
	
	@SuppressWarnings("unchecked")
	public static MMOffersT parseMonetaryMarket(InputStream inputStream) throws JAXBException {
		JAXBContext jc = JAXBContext.newInstance("org.erepublik.company.generated.monetarymarket");
		Unmarshaller u = jc.createUnmarshaller();
		JAXBElement jaxbEl = (JAXBElement) u.unmarshal( inputStream );
		MMOffersT jaxBObject = (MMOffersT) jaxbEl.getValue();
		return jaxBObject;
	}
	
	
	@SuppressWarnings("unchecked")
	public static TaxesT parseTaxes(InputStream inputStream) throws JAXBException {
		JAXBContext jc = JAXBContext.newInstance("org.erepublik.company.generated");
		Unmarshaller u = jc.createUnmarshaller();
		JAXBElement jaxbEl = (JAXBElement) u.unmarshal( inputStream );
		TaxesT jaxBObject = (TaxesT) jaxbEl.getValue();
		return jaxBObject;
	}

	   
    @SuppressWarnings("unchecked")
    public static CompanyT parseCompany(InputStream inputStream) throws JAXBException {
        JAXBContext jc = JAXBContext.newInstance("org.erepublik.company.generated");
        Unmarshaller u = jc.createUnmarshaller();
        JAXBElement jaxbEl = (JAXBElement) u.unmarshal( inputStream );
        CompanyT jaxBObject = (CompanyT) jaxbEl.getValue();
        return jaxBObject;
    }

    
    @SuppressWarnings("unchecked")
    public static RegionsTT parseRegions(InputStream inputStream) throws JAXBException {
        JAXBContext jc = JAXBContext.newInstance("org.erepublik.company.generated");
        Unmarshaller u = jc.createUnmarshaller();
        JAXBElement jaxbEl = (JAXBElement) u.unmarshal( inputStream );
        RegionsTT jaxBObject = (RegionsTT) jaxbEl.getValue();
        return jaxBObject;
    }
	
}
